<?php
session_start();
error_reporting(0);//tva spira pokazvaneto na vsi4ki greshkiii!!!!!!!!!!!!!!!!
if(!ob_start("ob_gzhandler")) ob_start();
	mysql_connect("localhost", "sapmenet_admin", "a1s2d3f4g5h6j7") or die ("Problem with datebase");
	mysql_select_db("sapmenet_users");
	
	if (isset($_SESSION['JID']))
	{
		$_SESSION['kelesh']=0;
		$check=mysql_query("SELECT email FROM users WHERE ID={$_REQUEST['id']}");
		if (mysql_num_rows($check)==0)
		{
			header ("HTTP/ 1.0 404 Not Found");
		}
		else{
		$_SESSION['id']=$_REQUEST['id'];
	
	
	
echo "
<html>
	<head>
		<title>SapMe</title>
		<link rel='shortcut icon' href='globeicon.ico'>
		<link rel = 'stylesheet' type = 'text/css' href='publicationsStyle.css'>
		<link rel = 'stylesheet' type = 'text/css' href = 'profilePageStyle.css'>
		<link rel = 'stylesheet' type = 'text/css' href = 'newsDialog.css'>
		<link rel = 'stylesheet' type = 'text/css' href = 'jquery-ui-1.8.18.custom.css'>
		<script type='text/javascript' src='jquery-1.7.js'></script>
		<script type = 'text/javascript' src = 'jquery-ui-1.8.16.custom.min.js'></script>
		<script type='text/javascript' src='profilePage.js'></script>
	</head>
	<body>
		
		<div id = 'loadDialog'>
		<div id = 'newsDialog'>
			<div id = 'newsDialogHeader'>
				<h3 id = 'newsDialogTitle'>
				</h3><img src='Icons/close.png' id='closeNews'>
			</div>
			<div id = 'newsDialogHeadless'>
			</div>
		</div>
		<div id='mainTab'>
		</div>
		<div id='tabless'>
		<div id='leftFrame'>
		</div>
		<div id='mainFrame'>";
		if (isset($_SESSION['JID']))
	{
		$userID=$_SESSION['JID'];
		$currentID=$_SESSION['id'];
		if ($userID!=$currentID){
		$fr=mysql_query("SELECT confirmed FROM friendships WHERE userID={$_SESSION['JID']} AND friendID={$_SESSION['id']}");
		if (mysql_num_rows($fr)<1)
		{
			echo"
			<div id = 'addFriend' class = 'theButtons' style = 'width:274px; text-align:center; margin-top:78px; margin-left:30px;'>
				<img src = 'addFriend.png' class = 'leftIcons'> Send friendship request
			</div>
			<script>
				$('#addFriend').click(function()
				{
					var userId = ".$_SESSION['JID'].";
					var anotherId = ".$_SESSION['id'].";
					$.post('invFriend.php', {user : userId, another : anotherId}, function(data)
					{
						$('#mainFrame').html('<div id = "."invitationSentSpan".">Invitation sent</div>');
					});
					
				});
			</script>";
			
		}
		else{
		$fr=mysql_result($fr,0);
		if ($fr){
		echo "<div id='textBox'>
			<form method = 'post' action = 'publications.php' id = 'addPublicationForm'>
				<textarea name='publicArea' id = 'addPublication' placeholder = 'Say something...'></textarea><br>
				<input type = 'submit' value ='Public' id='publicButton'><br>
			</form>
		</div>
		<div id='duvar'>
		</div>
		</div>
		<div id = 'rightFrame'>
		</div>
		</div>";
		}
		else {
		echo"<div id='sent'>Invitation sent</div>";
		}}
			/*<script>
			alert('ba4kam');
			$('.publication').click(function()
			{
				$('.publication').removeClass('Focus');
				$(this).addClass('Focus');
				var thePublicationId = $(this).attr('id');
				alert('thePublicationId');
			$('#deletePub').click(function()
			{
				$.post('deletePublication.php', {pubID: thePublicationId}, function()
				{
					$('#mainFrame').html('deletePublication.php');
				});
			});
		</script>
		
		<script>
		var mypic= $_SESSION['mainPic'];
	$('.publisher').mouseover(function()
		{ 
			$('#fiuuuPic').html("<img src="+mypic+">")
			
		});
		</script>
		*/
		
			 echo "</div></div></body>
</html>";
}
else {
echo "<div id='textBox'>
			<form method = 'post' action = 'publications.php' id = 'addPublicationForm'>
				<textarea name='publicArea' id = 'addPublication' placeholder = 'Say something...'></textarea><br>
				<input type = 'submit' value ='Public' id='publicButton'><br>
			</form>
		</div>
		<div id='duvar'>
		</div>
		</div>
		<div id = 'rightFrame'>
		</div>
		</div>";
}
}
}}
else{
		header ('Location: ..\index.php');
		exit();
	}
	?>
		